<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:uddi="urn:uddi-org:api_v3">
	<xsl:output method="xml" encoding="UTF-8"/>

	<xsl:include href="description.xsl"/>

	<!-- Match the contact UDDI element -->
	<xsl:template match="uddi:contact">
		<fieldset>
			<legend>Contact</legend>
			<xsl:apply-templates select="." mode="description"/>
			<xsl:apply-templates select="." mode="personName"/>
			<xsl:apply-templates select="." mode="phone"/>
			<xsl:apply-templates select="." mode="email"/>
			<xsl:apply-templates select="." mode="address"/>
		</fieldset>
	</xsl:template>

	<xsl:template match="*" mode="personName">
		<xsl:variable name="personNameCount"><xsl:value-of select="count(uddi:personName)"/></xsl:variable>
		<fieldset>
			<legend>Person Names [<xsl:value-of select="$personNameCount"/>]</legend>
			<xsl:if test="$personNameCount > 0">
				<ul>
					<xsl:apply-templates select="uddi:personName"/>
				</ul>
			</xsl:if>
		</fieldset>
	</xsl:template>

	<xsl:template match="*" mode="phone">
		<xsl:variable name="phoneCount"><xsl:value-of select="count(uddi:phone)"/></xsl:variable>
		<fieldset>
			<legend>Phone Numbers [<xsl:value-of select="$phoneCount"/>]</legend>
			<xsl:if test="$phoneCount > 0">
				<ul>
					<xsl:apply-templates select="uddi:phone"/>
				</ul>
			</xsl:if>
		</fieldset>
	</xsl:template>

	<xsl:template match="*" mode="email">
		<xsl:variable name="emailCount"><xsl:value-of select="count(uddi:email)"/></xsl:variable>
		<fieldset>
			<legend>Emails [<xsl:value-of select="$emailCount"/>]</legend>
			<xsl:if test="$emailCount > 0">
				<ul>
					<xsl:apply-templates select="uddi:email"/>
				</ul>
			</xsl:if>
		</fieldset>
	</xsl:template>

	<xsl:template match="*" mode="address">
		<xsl:variable name="addressCount"><xsl:value-of select="count(uddi:address)"/></xsl:variable>
		<fieldset>
			<legend>Addresses [<xsl:value-of select="$addressCount"/>]</legend>
			<xsl:if test="$addressCount > 0">
				<xsl:apply-templates select="uddi:address"/>
			</xsl:if>
		</fieldset>
	</xsl:template>


	<xsl:template match="uddi:personName">
		<li>
			<xsl:value-of select="."/>
		</li>
	</xsl:template>
	
	<xsl:template match="uddi:phone">
		<li>
			<xsl:value-of select="."/>
		</li>
	</xsl:template>

	<xsl:template match="uddi:email">
		<li>
			<a><xsl:attribute name="href">mailto:<xsl:value-of select="."/></xsl:attribute><xsl:value-of select="."/></a>
		</li>
	</xsl:template>
	
	<xsl:template match="uddi:address">
		<xsl:variable name="addressLineCount"><xsl:value-of select="count(uddi:addressLine)"/></xsl:variable>
		<fieldset>
			<legend>Address Lines [<xsl:value-of select="$addressLineCount"/>]</legend>
			<xsl:if test="$addressLineCount > 0">
				<ul>
					<xsl:apply-templates select="uddi:addressLineCount"/>
				</ul>
			</xsl:if>
		</fieldset>

		<li>
			<xsl:value-of select="."/>
		</li>
	</xsl:template>
	
	<xsl:template match="uddi:addressLine">
		<li>
			<xsl:value-of select="."/>
		</li>
	</xsl:template>
</xsl:stylesheet>